ThienTanFormPanel = Ext.extend(Ext.form.FormPanel, {
    layout : 'form',
    submitButtons : [],

    /**
     * @override from Ext.grid.FormPanel
     * Add an instance Ext.oxy.FormMessage to display message in form automatically.
     */
    initComponent : function(){
    	ThienTanFormPanel.superclass.initComponent.call(this);
    	
    	this.formMessage = new FormMessage({
            autoHeight : true,
            hidden : true
        });
        
        //insert FormMessage on the top of ThienTanFormPanel
        this.insert(0, this.formMessage);
    },
    
    render : function(container, position){
    	ThienTanFormPanel.superclass.render.call(this, container, position);
    },
    /**
     * @override form Ext.grid.FormPanel
     */
    onRender : function(ct, position){
    	ThienTanFormPanel.superclass.onRender.call(this, ct, position);
    },
    
    notifyMessage : function(msg) {
        var visible = false;
        if(msg.action == 'info') {
            this.formMessage.showMessages(
                    [FormMessageType.INFO], [msg.msg]);
            visible = true;
        } else if (msg.action == 'warn') {
            this.formMessage.showMessages(
                    [FormMessageType.WARNING], [msg.msg]);
            visible = true;
        } else if (msg.action == 'error') {
            this.formMessage.showMessages(
                    [FormMessageType.ERROR], [msg.msg]);
            visible = true;
        } else {
            this.formMessage.clearMessages();
            visible = false;
        }
        this.formMessage.setVisible(visible);
        this.doLayout();
    },
    
    addMessages : function(type, msgArray){
        this.formMessage.addMessages(type, msgArray);
        this.formMessage.setVisible(true);
        this.doLayout();
    },
    
    /**
     * @override from Ext.grid.FormPanel
     */
    afterRender : function() {
    	ThienTanFormPanel.superclass.afterRender.call(this);
    	this.form.on('infoMessage', this.notifyMessage, this);
    },
    
    /**
     * @override from Ext.grid.FormPanel
     */
    createForm : function(){
        var config = Ext.applyIf({listeners: {}}, this.initialConfig);
        return new ThienTanBasicForm(null, config);
    },
    
    disableButtons : function() {
    	if(Ext.isArray(this.submitButtons)){
            var size = this.submitButtons.length;
            for(var i=0; i<size ; i++){
                var btn = this.submitButtons[i];
                if(btn && btn.el && btn.el.dom){
                    btn.disable();
                }
            }
        }
    },
    
    enableButtons : function() {
    	if(Ext.isArray(this.submitButtons)){
            var size = this.submitButtons.length;
            for(var i=0; i<size ; i++){
                var btn = this.submitButtons[i];
                if(btn && btn.el && btn.el.dom){
                    btn.enable();
                }
            }
        }
    }
});
